package wqh.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import wqh.domain.DtAlarmEvent;
import wqh.pojo.MapRet;
import wqh.service.DtAlarmEventService;

import java.util.List;
/**
 * Created by cfs on 2016/12/16.
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("water/dt_alarm_event")
public class DtAlarmEventJSONController {
    private static org.slf4j.Logger logger = LoggerFactory.getLogger(DtAlarmEventJSONController.class);

    @Autowired
    private DtAlarmEventService dtAlarmEventService;
    @RequestMapping(value = "getDtData",method = RequestMethod.GET)
    public Object getDtData(@RequestParam(value = "draw",required = true)int draw,
                          @RequestParam(value = "start",required = true)int start,
                          @RequestParam(value = "length",required = true)int length
    )
    {
        try{
            PageHelper.startPage(start/length+1,length);
            List<DtAlarmEvent> dtAlarmEventList = dtAlarmEventService.findAllRecord();
            Integer count = dtAlarmEventService.selectCount();
            PageInfo page = new PageInfo(dtAlarmEventList);
            return MapRet.DATATABLES(draw,count,new Long(page.getTotal()).intValue(),dtAlarmEventList);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("显示动态监测报警事件异常"+e.getMessage());
            return MapRet.SQL_ERROR(e);
        }
    }


}
